write-host "Setting NotificationJobDelay..."

# http://blogs.msdn.com/b/granth/archive/2009/10/28/tfs2010-diagnosing-email-and-soap-subscription-failures.aspx


[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")

# Modify the TFS configuration server URL as necessary.
$configServer = new-object Microsoft.TeamFoundation.Client.TfsConfigurationServer "http://localhost:8080/tfs/"

# Get the TF registry service.
$tfsRegService = $configServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamFoundationRegistry])

# Set the notification delay to 0 seconds. All collections will use this delay unless they override this value in the collection hive.
$tfsRegService.SetValue("/Service/Integration/Settings/NotificationJobDelay", 0)

write-host Recycle Microsoft Team Foundation Server Application Pool for this change to take effect


write-host "Setting NotificationJobLogLevel..."

# Use this query after setting this entry:
#SELECT TOP 10 StartTime as StartTimePDT, Result, ResultMessage
#FROM [Tfs_Configuration].[dbo].[tbl_JobHistory]
#WHERE JobId = 'A4804DCF-4BB6-4109-B61C-E59C2E8A9FF7' AND Result <> 0
#ORDER BY StartTime DESC

# Increase the logging level (set back to 0 under normal operating conditions)
$collectionBaseUrl = "http://tfs:8080/tfs/TWA/";

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($collectionBaseUrl); 
$collectionHive = $tfs.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamFoundationRegistry]);

# Set the setting in the collection hive. 
$collectionHive.SetValue("/Service/Integration/Settings/NotificationJobLogLevel", "2");


write-host "End of script."
